package mvc.struts.form;

import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class MyContextListener implements ServletContextListener {

	/**
	 * 
	 * @param arg0
	 */
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		
		System.out.println("Context destroyed");
	}

	/**
	 * 
	 * @param arg0
	 */
	@Override
	public void contextInitialized(ServletContextEvent arg0) {

		ServletContext	servletContext;
		
		servletContext = arg0.getServletContext();
		
		String	xmlpath 	= 	servletContext.getInitParameter("servletParam");
		String	tomcatpath 	= 	servletContext.getRealPath("\\");

		System.out.println("tomcatpath = " + tomcatpath);
		System.out.println("xmlpath = " + xmlpath);
		System.out.println("tomcatpath + xmlpath = " + tomcatpath + xmlpath);
		
		try 
		{
			Map<String, XmlBean>	map = StrutsXml.Struts_Xml(tomcatpath + xmlpath);
			
			servletContext.setAttribute("struts", map);
		} 
		catch (Exception e) {
			
			e.printStackTrace();
		}
		
		System.out.println("Context initialized");
	}
}
